package com.ywq.app.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ywq.app.dao.ArtActivityDao;
import com.ywq.app.domain.ArtActivity;
import com.ywq.app.domain.ArtActivityMember;
import com.ywq.common.exception.AppBusinessException;

public class ArtActivityDaoImpl extends SqlSessionDaoSupport implements ArtActivityDao{
	
	private static final Logger logger = LoggerFactory.getLogger(ArtActivityDaoImpl.class);
	
	/**
	 * 总数
	 */
	@Override
	public int getArtActivityListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtActivityMapper.getArtActivityListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtActivityListCount user failure.", e);
			}
			throw new AppBusinessException("getArtActivityListCount user failure.", e);
		}
	}
	/**
	 * 活动列表
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtActivity> getArtActivityList(Map<String, Object> map)
			throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtActivityMapper.getArtActivityList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtActivityList list failure.", e);
			}
			throw new AppBusinessException("getArtActivityList list failure.", e);
		}
	}
	/**
	 * 新增活动
	 */
	@Override
	public void insertArtActivity(ArtActivity artActivity) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtActivityMapper.insertArtActivity",
							artActivity);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtActivity user failure.", e);
			}
			throw new AppBusinessException("insertArtActivity user failure.", e);
		}
	}
	/**
	 * 更新活动
	 */
	@Override
	public void updateArtActivity(ArtActivity artActivity) throws AppBusinessException {
		try {
			getSqlSession()
					.update("com.ywq.app.persistence.ArtActivityMapper.updateArtActivity",
							artActivity);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateArtActivity user failure.", e);
			}
			throw new AppBusinessException("updateArtActivity user failure.", e);
		}
	}
	@Override
	public void deleteActivity(Map<String, Object> map) throws AppBusinessException {
		try {
			getSqlSession()
					.update("com.ywq.app.persistence.ArtActivityMapper.deleteActivity",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateArtActivity user failure.", e);
			}
			throw new AppBusinessException("updateArtActivity user failure.", e);
		}
	}
	
	//当前活动
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtActivity> getNowActivityList(Map<String, Object> map)throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtActivityMapper.getNowActivityList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getNowActivityList list failure.", e);
			}
			throw new AppBusinessException("getNowActivityList list failure.", e);
		}
	}
	//历史活动
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtActivity> getOldActivityList(Map<String, Object> map)throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtActivityMapper.getOldActivityList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getOldActivityList list failure.", e);
			}
			throw new AppBusinessException("getOldActivityList list failure.", e);
		}
	}
	//历史活动个数
	@Override
	public int getOldActivityListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtActivityMapper.getOldActivityListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getOldActivityListCount user failure.", e);
			}
			throw new AppBusinessException("getOldActivityListCount user failure.", e);
		}
	}
	//单个活动
	@Override
	public ArtActivity getArtActivityById(Map<String, Object> map)throws AppBusinessException {

		try {
			return (ArtActivity) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtActivityMapper.getArtActivityById",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtActivityById list failure.", e);
			}
			throw new AppBusinessException("getArtActivityById list failure.", e);
		}
	}
	//参加活动
	
	@Override
	public void insertArtActivityMember(ArtActivityMember artActivityMember) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtActivityMapper.insertArtActivityMember",
							artActivityMember);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtActivityMember user failure.", e);
			}
			throw new AppBusinessException("insertArtActivityMember user failure.", e);
		}
	}
	//
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtActivityMember> artPersonList(Map<String, Object> map)throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtActivityMapper.artPersonList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("artPersonList list failure.", e);
			}
			throw new AppBusinessException("artPersonList list failure.", e);
		}
	}
	@Override
	public int artPersonListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtActivityMapper.artPersonListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("artPersonListCount user failure.", e);
			}
			throw new AppBusinessException("artPersonListCount user failure.", e);
		}
	}
}
